package cz.proks.easyhelpdesk.gwt.restapi;

import java.util.Collection;

import org.jsonmaker.gwt.client.Jsonizer;

import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONValue;

import cz.proks.easyhelpdesk.api.config.Configuration;
import cz.proks.easyhelpdesk.api.model.Helpdesk;
import cz.proks.easyhelpdesk.api.model.HelpdeskJsonizer;
import cz.proks.easyhelpdesk.gwt.utils.JsonizerUtils;
import cz.proks.easyhelpdesk.gwt.utils.RestUtils;

public class HelpdeskRestApi extends BaseRestApi<Helpdesk>{
    private final static Jsonizer JSONIZER = GWT.create(HelpdeskJsonizer.class);

    @Override
    protected String getBaseRestDomainUrlPart() {
        return Configuration.WS.HELPDESK_BASE_URL;
    }

    @Override
    protected Jsonizer getDomainJsonizer() {
        return JSONIZER;
    }    
    
    public void listForUser(Long userId, final DomainListCallback<Helpdesk> callback) {
        RestUtils.makeRestRequest(getBaseDomainUrl() + "/listForUser/" + userId, new RestUtils.Callback(callback) {
            
            @Override
            public void onSuccess(JSONValue val) {
                Collection<Helpdesk> helpdesks = JsonizerUtils.getListFromJsonArray(val, JSONIZER);
                callback.onDomainListSuccess(helpdesks);
            }          
        });
    }
}
